//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "common\fn_actionGetLocal.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_object","_action","_key","_default","_result","_actions","_id","_index","_local_action"];
DEFAULT_PARAM(_object,0,objNull);
DEFAULT_PARAM(_action,1,[]);
DEFAULT_PARAM(_key,2,"");
DEFAULT_PARAM(_default,3,nil);
_actions = (call CFUNC(hashEmpty));
_result = _default;
_actions = OGETVAR(_object,QGVAR(LOCAL_MISSION_ACTIONS),_actions);
TRACE_1("LocalMissionActions",_actions);
_id = [_action, "__ACTION_ID__",-1] call CFUNC(HashGet);
_index = -1;
if (_id >= 0 && count _actions > 0) then {
	for [{_i = 0},{_i < count _actions},{_i = _i + 1}] do {
		if (_id == ([(_actions select _i), "__ACTION_ID__",-1] call CFUNC(HashGet))) exitWith {_index = _i};
	};
};
TRACE_2("Found index",_index,(count _actions));
if (_index >= 0) then {
	_local_action = (_actions select _index);
	_result = ([_local_action, _key,_result] call CFUNC(HashGet));
};
TRACE_1("End",_result);
TMFPROFILERSTOP;
_result;